package com.hbnu.controller;

import com.hbnu.pojo.DormBuild;
import com.hbnu.pojo.User;
import com.hbnu.service.UserService;
import com.hbnu.service.impl.DormManagerServiceImpl;
import com.hbnu.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 宿舍管理员管理
 *      请求地址：http://localhost:8080/dormManager.action?action=list
 *      请求方式：GET
 *      请求参数：action:list
 *
 * @author chendikai
 * @date 2024-11-13 下午 2:53
 */
@WebServlet("/dormManager.action")
public class DormManagerServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String action = req.getParameter("action");

        if ("list".equals(action)) {

            String searchType = req.getParameter("searchType");
            String keyword = req.getParameter("keyword");

            // 查询出所有的宿舍管理员信息
            List<User> userList = userService.findAllManager(searchType, keyword);

            req.setAttribute("searchType", searchType);
            req.setAttribute("keyword", keyword);
            req.setAttribute("users", userList);
            req.setAttribute("mainRight", "dormManagerList.jsp");
            req.getRequestDispatcher("/jsp/main.jsp").forward(req, resp);

        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
//
//    @WebServlet("/dormManager.action")
//    public class DormManageServlet extends HttpServlet {
//
//        UserService userService = new UserServiceImpl();
//
//        DormBuildService buildService = new DormManagerServiceImpl();
//
//        @Override
//        protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//
//            request.setCharacterEncoding("UTF-8");
//
//            String action = request.getParameter("action");
//
//            String id = request.getParameter("id");
//
//            List<DormBuild> builds = buildService.find();
//            request.setAttribute("builds",builds);
//
//            if (null != action && action.equals("list")) {
//                String searchType = request.getParameter("searchType");
//                String keyword = request.getParameter("keyword");
//
//                // 查询宿舍管理员
//                List<User> users = userService.findAllManager(searchType, keyword);
//
//                request.setAttribute("searchType", searchType);
//                request.setAttribute("keyword", keyword);
//                request.setAttribute("users", users);
//                request.setAttribute("mainRight", "dormManagerList.jsp");
//                request.getRequestDispatcher("/jsp/main.jsp").forward(request, response);
//
//
//            }
//        }
//
//    }


}










